package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.dto.product.CategoryExcelDto;
import com.atguigu.spzx.model.pojo.product.Category;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.utils.DYLAssert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dyl
 * @version 1.0
 * @description:
 * @date 2025/1/5 20:27
 */
@RestController
@RequestMapping("/admin/product/category")
@CrossOrigin(allowCredentials = "true", originPatterns = "*", allowedHeaders = "*")
@Tag(name = "商品分类管理")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/findByParentId/{parentId}")
    @Operation(summary = "加载子分类")
    public Result<List<Category>> findByParentId(@PathVariable("parentId") Long parentId){
        DYLAssert.notNull(parentId, "查询失败，parentId为空");
        List<Category> list = categoryService.findByParentId(parentId);
        return Result.ok(list);
    }

    @GetMapping("/exportData")
    @Operation(summary = "导出数据")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }
}
